<?php
define('MY_ROOT',dirname(__FILE__));
define('PACKAGE','weixin');
require(MY_ROOT.'/source/core.php');
require_once(MY_ROOT.'/config/weixin.php');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$core=core::instance();
$core->init();
require_once(MY_ROOT.'/source/class/weixin.php');
require_once(MY_ROOT.'/source/class/smuwx.php');
$wxh=new weixin($config['weixin']);
if(isset($_GET['signature'])&&($_SERVER['REQUEST_METHOD']=='GET'))
{
if($wxh->checkSignature($_GET['signature'],$_GET['timestamp'],$_GET['nonce']))
{
echo $_GET['echostr'];
throw new Exception();
}else{
	echo 'error';
	throw new Exception();
	}
}
$data=$wxh->getmsg();
$out['to']=$data['to'];
$out['from']=$data['from'];
if($data['type']=='event')
{
SMUWX::event($data,$type,$out);
}
elseif(preg_match('/#/',$data['content']))
{
	SMUWX::cmdexec($data,$type,$out);
}
else{
	SMUWX::prase($data,$type,$out);
}
$wxh->response($type,$out);
?>
